/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-10-08 09:36:19
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-08 09:36:24
 */
import java.util.Comparator;
import java.util.TreeSet;

public class Test05_3_Teachers {
    public static void main(String[] args) {
        // 定义 TreeSet 集合并传入一个自定义比较规则的 Comparator
        TreeSet<Teacher> set = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher t1, Teacher t2) {
                int nameComparison = t1.getName().compareTo(t2.getName());
                if (nameComparison != 0) {
                    return nameComparison;
                }

                int ageComparison = Integer.compare(t1.getAge(), t2.getAge());
                if (ageComparison != 0) {
                    return ageComparison;
                }

                return Integer.compare(t1.getId(), t2.getId());
            }
        });

        // 测试数据
        Teacher teacher1 = new Teacher(1, "Tom", 30);
        Teacher teacher2 = new Teacher(2, "Mike", 25);
        Teacher teacher3 = new Teacher(3, "Lily", 22);
        Teacher teacher4 = new Teacher(4, "Chris", 23);
        Teacher teacher5 = new Teacher(5, "Tom", 25);

        set.add(teacher1);
        set.add(teacher2);
        set.add(teacher3);
        set.add(teacher4);
        set.add(teacher5);

        // 遍历并输出
        for (Teacher teacher : set) {
            System.out.println(teacher);
        }
    }
}